package com.m3958.firstgwt.client.utils;

import java.util.Map;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.m3958.firstgwt.client.resource.FirstGwtResource;
import com.m3958.firstgwt.client.types.ViewNameEnum;
import com.m3958.gwtutil.clientside.client.utils.ClientStringUtils;

@Singleton
public class HelpUrlMap {
	
	@Inject
	private FirstGwtResource fgResource;
	
	private Map<String, String> humap;
	
	@Inject
	private ClientStringUtils csu;
	
	private boolean mapHasBuilder = false;
	
	public String getUrl(String key){
		if(!mapHasBuilder){
			mapHasBuilder = true;
			String s = fgResource.helpUrlMap().getText();
			s = s.replaceAll("\\s+", "");
			humap = csu.pair2hash(s);
		}
		return humap.get(key);
	}
	
	public String getUrl(ViewNameEnum vn){
		String key = vn.toString();
		if(!mapHasBuilder){
			mapHasBuilder = true;
			String s = fgResource.helpUrlMap().getText();
			humap = csu.pair2hash(s);
		}
		return humap.get(key);
	}
}
